﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YouFood.DAL.BusinessObject
{
    public class Restaurant : BusinessObject, IBusinessObject
    {
        private const string NAME_LENGHT_ERROR = "Name cannot be longer than 100 char";
        private const string NAME_NULL_ERROR = "Name cannot be null";
        private const string ADDRESS_LENGHT_ERROR = "Address cannot be longer than 200 char";
        private const string ADDRESS_NULL_ERROR = "Address cannot be null";
        private const int NAME_LENGHT_MAX = 100;
        private const int ADDRESS_LENGHT_MAX = 200;

        public Guid RestaurantId { get; private set; }

        //Lenght: 100
        public string Name { get; set; }

        //Lenght: 200
        public string Address { get; set; }

        public ValidationResult Save()
        {
            ValidationResult result = BeforeSave();

            if (result.Errors.Count == 0)
            {
                RestaurantId = Guid.NewGuid();

                result.SavedObject = this;

                Restaurant restaurantSave = new Restaurant();


            }

            return result;
        }

        public bool BeforeSave(ref ValidationResult validationResult)
        {
            throw new NotImplementedException();
        }

        public ValidationResult BeforeSave()
        {
            ValidationResult result = new ValidationResult();

            if (Name == null)
            {
                result.Errors.Add(NAME_NULL_ERROR);
            }
            else
            {
                if (Name.Length > NAME_LENGHT_MAX)
                {
                    result.Errors.Add(NAME_LENGHT_ERROR);
                }
            }

            if (Address == null)
            {
                result.Errors.Add(ADDRESS_NULL_ERROR);
            }
            else
            {
                if (Address.Length > ADDRESS_LENGHT_MAX)
                {
                    result.Errors.Add(ADDRESS_LENGHT_ERROR);
                }
            }

            return result;
        }
    }
}
